package com.amtf.datafile3.cfg.excel;

import java.util.List;

import org.apache.poi.ss.usermodel.FormulaEvaluator;

import com.amtf.datafile3.DataFieldDefinition;
import com.amtf.datafile3.cfg.std.StdDataTableDefinition;
import com.amtf.datafile3.core.excel.parser.AbsExcelDataFieldParser;
import com.amtf.datafile3.core.excel.parser.ExcelDataRecordParser;
import com.amtf.datafile3.core.xsv.render.XsvDataFieldRender;

public class ExcelDataTableDefinition extends StdDataTableDefinition {
	private int firstReadingRow = 0;
	// private int firstReadingColumn = 0;
	// private int maxReadingRow = 1048576;// 65535;
	// private int maxReadingColumn = 16384;// 256;
	private int firstWritenRow = 0;
	private int firstWritenColumn = 0;

	private boolean firstRowTitle;

	public ExcelDataTableDefinition(String name, boolean firstRowTitle, int firstReadingRow, int firstReadingColumn, int firstWritenRow, int firstWritenColumn,
			FormulaEvaluator evaluator) {
		super(name, new ExcelDataRecordParser(evaluator, firstReadingColumn), null);
		this.firstReadingRow = firstReadingRow;
		// this.firstReadingColumn = firstReadingColumn;
		this.firstWritenRow = firstWritenRow;
		this.firstWritenColumn = firstWritenColumn;
		this.firstRowTitle = firstRowTitle;
	}

	@Override
	public ExcelDataTableDefinition clone() {
		ExcelDataTableDefinition cloneDef = new ExcelDataTableDefinition(name, firstRowTitle, firstReadingRow, 0, firstWritenRow, firstWritenColumn, getEvaluator());
		copyTo(cloneDef);
		return cloneDef;
	}

	public boolean isFirstRowTitle() {
		return firstRowTitle;
	}

	public void setFirstRowTitle(boolean firstRowTitle) {
		this.firstRowTitle = firstRowTitle;
	}

	public int getFirstReadingRow() {
		return firstReadingRow;
	}

	public void setFirstReadingRow(int firstReadingRow) {
		this.firstReadingRow = firstReadingRow;
	}

	public int getFirstReadingColumn() {
		return ((ExcelDataRecordParser) parser).getFirstColumn();
	}

	public void setFirstReadingColumn(int firstReadingColumn) {
		((ExcelDataRecordParser) parser).setFirstColumn(firstReadingColumn);
	}

	public int getFirstWritenRow() {
		return firstWritenRow;
	}

	public void setFirstWritenRow(int firstWritenRow) {
		this.firstWritenRow = firstWritenRow;
	}

	public int getFirstWritenColumn() {
		return firstWritenColumn;
	}

	public void setFirstWritenColumn(int firstWritenColumn) {
		this.firstWritenColumn = firstWritenColumn;
	}

	public FormulaEvaluator getEvaluator() {
		return ((ExcelDataRecordParser) parser).getEvaluator();
	}

	public void setEvaluator(FormulaEvaluator evaluator) {
		((ExcelDataRecordParser) parser).setEvaluator(evaluator);
		List<DataFieldDefinition> fields = this.getFields();
		for (DataFieldDefinition dataFieldDefinition : fields) {
			AbsExcelDataFieldParser ps = (AbsExcelDataFieldParser) dataFieldDefinition.getParser();
			ps.setEvaluator(evaluator);
		}
	}

}
